﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlServerCe;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LDataAccess;
using LModels;

namespace LClient
{
    public partial class MDI : Form
    {
        ProxyManager pm = new ProxyManager();

        public MDI()
        {
            InitializeComponent();
            pm.AddProxy("lidarDB", new Proxy());

            //LModels.Models.Workspace w = new Models<LModels.Models.Workspace>(DB).Instance;
            //w.Load(1);

            //MessageBox.Show(w.Date.ToString());

            // Carico la TreeView
            LoadTreeview();
        }

        private void LoadTreeview()
        {

            Models.Collections.WorkspaceCollection wc =
                           new Models.FactoryCollection<Models.Collections.WorkspaceCollection>(pm.GetProxy("lidarDB")).GetInstance();

            grdWorkspaces.DataSource = wc.List();

        }

        private void grvWorkspaces_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            //Validating selected row
            if (e.RowHandle < 0)
            {
                //Writing code for invalid row selected
            }
            else
            {
                //Models.Workspace workspace = (Models.Workspace)grvWorkspaces.GetRow(e.RowHandle);
                long ID = (long)(grvWorkspaces.GetRowCellValue(e.RowHandle, "IDWorkspace"));
                MessageBox.Show(ID.ToString());

                Models.Collections.RecordingCollection Recordings =
                    new Models.FactoryCollection<Models.Collections.RecordingCollection>(pm.GetProxy("lidarDB")).GetInstance();

                grdRecordings.DataSource = Recordings.ListById(ID);

            }

        }

    }

}
